package com.kfm.movie;

import java.util.Objects;

public class Movie {

    private String name;
    private double price;
    private String director;
    private int date;

    public int getTickets() {
        return tickets;
    }

    public void setTickets(int tickets) {
        this.tickets = tickets;
    }

    private int tickets;

    public Movie() {
    }

    public Movie(Movie movie, int count) {
        this(movie.getName(), movie.getPrice(), movie.getDirector(), movie.getDate(), movie.getTickets());
        this.tickets = count;
    }

    public Movie(String name, double price, String director, int date, int tickets) {
        this.name = name;
        this.price = price;
        this.director = director;
        this.date = date;
        this.tickets = tickets == 0 ? 10 : tickets;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    public String getDirector() {
        return director;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public int getDate() {
        return date;
    }

    public void setDate(int date) {
        this.date = date;
    }

    // println() 方法调用的是对象的toString()方法
    @Override
    public String toString() {
        return "Movie{" +
                "电影名称：'" + name + '\'' +
                ", 电影价格：" + price +
                ", 导演：'" + director + '\'' +
                ", 上映日期：" + date +
                ", 票数：" + tickets +
                '}';
    }

    public boolean equals(Object obj) {
        // this 和obj 去比较
        if (this == obj) {
            return true;
        }
        if (obj instanceof Movie movie) { // 16新增的
//            Movie movie = (Movie) obj;
//            if (this.name.equals(movie.getName())
//                    && this.director.equals(movie.getDirector())
//                    && this.date == movie.getDate()
//                    && this.price == movie.getPrice()) {
//                return true;
//            }
            if (Objects.equals(this.name, movie.getName()) &&
                    Objects.equals(this.director, movie.getDirector())
                    && this.date == movie.getDate()
                    && this.price == movie.getPrice()) {
                return true;
            }
        }
        return false;
    }


}
